/*
 * msgHeaderDefs.h
 *
 * Created: 6/18/2013 2:16:48 AM
 *  Author: Tim
 */ 


#ifndef MSGHEADERDEFS_H_
#define MSGHEADERDEFS_H_

#include <inttypes.h>

#include "../../features/allocations.h"

#include "adcPacketStructs.h"
#include "dacPacketStructs.h"
#include "dioPacketStructs.h"
#include "encPacketStructs.h"
#include "genPacketStructs.h"
#include "tmrPacketStructs.h"
#include "pwmPacketStructs.h"

#define outpuPacketLength_MAX	22

//same for all messages
#define packetHeader			0x55	//85

//message header index

/************GEN***************/
	
#define general_mh_msk			0xF0	//240

#define ack_mh					0xFE	//254

#define resetDaq_mh				0xFD	//253

#define startProgram_mh			0xFC	//252

#define stopProgram_mh			0xFB	//251

#define daqReady_mh				0xFA	//250

/************ADC***************/

#define adc_mh_msk				0x00

#define adcInit_mh				0x01	

/************DAC***************/

#define dac_mh_msk				0x10	//16

#define dacEnable_mh			0x11	//17

/************DIO***************/

#define dio_mh_msk				0x20	//32

#define digitalInEnable_mh		0x21	//33

#define digitalOutEnable_mh		0x22	//34

/************ENC***************/

#define enc_mh_msk				0x30	//48

#define encInit_mh				0x31	//49

/************TMR***************/

#define tmr_mh_msk				0x40	//64

#define tmrSetFreq_mh			0x41	//65


/************PWM***************/

#define pwm_mh_msk				0x50	//80

#define	servoEnable_mh			0x51	//81
	
#define	motorEnable_mh			0x52	//82

/***********SUPER**************/

#define SuperPacket_mh_msk		0x60	//96

#define outputSuperPacket_mh	0x61	//97

#define inputSuperPacket_mh		0x62	//98

#define actuatorSuperPacket_mh	0x63	//99


static inline uint16_t packetSizeLookup(uint8_t msgeHeader)
{
	
	/*
		need to incorporate dynamic messages (super packets)
		these messages will return a variable length based on the current state
	*/
	
	switch(msgeHeader)
	{
		//general messages
		case ack_mh:
			return	sizeof(xtrg_t);
		break;
		case resetDaq_mh:
			return	sizeof(resetDaq_t);
		break;
		case startProgram_mh:
			return	sizeof(programStart_t);
		break;
		case stopProgram_mh:
			return	sizeof(programStop_t);
		break;
		case daqReady_mh:
			return	sizeof(daqReady_t);
		break;
		//adc messages
		case adcInit_mh:
			return	sizeof(adcInit_t);
		break;
		//dac messages
		case dacEnable_mh:
			return	sizeof(dacEnable_t);
		break;
		//dio messages
		case (digitalInEnable_mh):
			return	sizeof(digitalInEnable_t);
		break;
		case (digitalOutEnable_mh):
			return	sizeof(digitalOutEnable_t);
		break;
		//encoder messages
		case encInit_mh:
			return	sizeof(encInit_t);
		break;
		//pwm messages
		case (servoEnable_mh):
			return sizeof(servoEnable_t);
		break;
		case (motorEnable_mh):
			return sizeof(motorEnable_t);
		break;
		//tmr messages
		case (tmrSetFreq_mh):
			return sizeof(tmrSetFreq_t);
		break;
		//SuperPackets
		case outputSuperPacket_mh:
			return outputSuperPacketLength;
		break;
		case inputSuperPacket_mh:
			return inputSuperPacketLength;
		break;
		case actuatorSuperPacket_mh:
			return actuatorSuperPacketLength;
		break;
		
	}
	//for whatever reason I cannot get the default keyword to be recognized so here is a catch all
	return 0;	//bad message header
			
}

#endif /* MSGHEADERDEFS_H_ */